package com.ffapp.demo.bean;


import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;

public class UserSquadronListBean extends BaseListBeanBc {

    private ArrayList<UserSquadronListData> list = new ArrayList<UserSquadronListData>();

    public ArrayList<UserSquadronListData> getList() {
        return list;
    }

    public void setList(ArrayList<UserSquadronListData> list) {
        this.list = list;
    }

    @JSONField(serialize = false)
    public  String[] getListStringGroup(){
        if(list == null || list.size() == 0)return new String[]{};
        String[] listString = new String[list.size()];
        int i = 0;
        for(UserSquadronListData data:list){
            listString[i] = data.getName();
            i++;
        }
        return  listString;
    }
    @JSONField(serialize = false)
    public  int getCheckedPosition(UserSquadronListData checkedData){
        if(checkedData == null){
            return -1;
        }
        int i = 0;
        for(UserSquadronListData data:list){
            if(data.getId().equals(checkedData.getId())){
                return i;
            }
            i++;
        }
        return  -1;
    }

    public UserSquadronListData getDataByAreaName(String areaname){
        if(list == null ||list.size() == 0){
            return null;
        }
        if(TextUtils.isEmpty(areaname))return list.get(0);
        for(UserSquadronListData data:list){
            if(!TextUtils.isEmpty(data.getAreaName()) && data.getAreaName().contains(areaname)){
                return  data;
            }
        }
        return  list.get(0);
    }


    public UserSquadronListData getDataByAreaNameAndCurrent(String areaname,UserSquadronListData dataCurrent){

        if(list == null ||list.size() == 0){
            return dataCurrent;
        }
        if(!TextUtils.isEmpty(areaname) && dataCurrent != null && !TextUtils.isEmpty(dataCurrent.getAreaName()) && dataCurrent.getAreaName().contains(areaname)){
            return dataCurrent;
        }
        if(TextUtils.isEmpty(areaname)){
            if(dataCurrent != null)return dataCurrent;
            return list.get(0);
        }
        for(UserSquadronListData data:list){
            if(!TextUtils.isEmpty(data.getAreaName()) && data.getAreaName().contains(areaname)){
                return  data;
            }
        }
        if(dataCurrent != null)return dataCurrent;
        return  list.get(0);
    }

}
